﻿using AESAlgNet;
using Sunny.UI;
using System.Drawing;

namespace AESAlgDemo
{
    public partial class FormALGDemo : UIForm
    {
        public FormALGDemo()
        {
            InitializeComponent();

        }

        private void uiButtonTest_Click(object sender, System.EventArgs e)
        {
            //AESALG2D.TestStruct TS = new AESALG2D.TestStruct();
            //TS.a = 1; TS.b = 2;TS.c = 3;
            //TS.d = new int[8] { 1,2,3,4,5,6,7,8};
            //TS.e = new float[10] { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 0.11f, };
            //TS.f = new double[12] { 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.1, 3.1, 4.1, };
            //_ = AESALG2D.T(TS);

            Bitmap bitmap = (Bitmap)Bitmap.FromFile(@"D:\Desktop\1.png");
            byte[] bytes = ImageTools.BitmapToRGBByteArray(bitmap);

            double[] mtf = new double[128];
            double[] freq = new double[128];

            double useFreq = 0.1;
            double mtfValue = 0.0;

            AESALG2D.SFR(bytes, bitmap.Width, bitmap.Height, 0.003, useFreq, ref mtfValue, mtf, freq);

            UILineOption option = new UILineOption();
            option.ToolTip.Visible = true;//提示信息

            option.Title = new UITitle();//标题设置
            option.Title.Text = $"SFR 曲线";
            option.Title.SubText = "";

            option.XAxis.Name = "cy/px";
            option.XAxis.MaxAuto = true;
            option.XAxis.MinAuto = true;


            option.YAxis.Name = $"MTF[{mtfValue:N2}]";//Y轴设置
            option.YAxis.MinAuto = true;
            option.YAxis.Max = 1.0;

            UILineSeries series = option.AddSeries(new UILineSeries("扭力曲线", Color.Red));//创建系列

            for (int i = 0; i < mtf.Length; i++)
            {
                if (mtf[i] == 0) break;
                series.Add(freq[i], mtf[i]);
            }

            uiLineChartSFR.SetOption(option);
        }
    }
}
